﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using TyMES.Model.BaseInformation;
using TyMES.Model;

namespace TyMES.ViewModel.BaseInformation.PersonVMs
{
    public partial class PersonListVM : BasePagedListVM<Person_View, PersonSearcher>
    {
        
        protected override IEnumerable<IGridColumn<Person_View>> InitGridHeader()
        {
            return new List<GridColumn<Person_View>>{
                
                this.MakeGridHeader(x => x.Person_PersonCode).SetTitle(@Localizer["Page.员工编号"].Value).SetSort(true),
                this.MakeGridHeader(x => x.Person_PersonName).SetTitle(@Localizer["Page.员工名称"].Value).SetSort(true),
                this.MakeGridHeader(x => x.Person_PhoneNumber).SetTitle(@Localizer["_Admin.CellPhone"].Value).SetSort(true),
                this.MakeGridHeader(x => x.Person_Gender).SetTitle(@Localizer["_Admin.Gender"].Value).SetSort(true),
                this.MakeGridHeader(x => x.Person_Address).SetTitle(@Localizer["_Admin.Address"].Value).SetSort(true),
                this.MakeGridHeader(x => x.Person_EmpSkills).SetTitle(@Localizer["Page.技能级别"].Value).SetSort(true),
                this.MakeGridHeader(x => x.Person_StationCode).SetTitle(@Localizer["Page.工位编码"].Value).SetSort(true),
                this.MakeGridHeader(x => x.Person_LineCode).SetTitle(@Localizer["Page.产线编码"].Value).SetSort(true),

                this.MakeGridHeaderAction(width: 200)
            };
        }

        
        public override IOrderedQueryable<Person_View> GetSearchQuery()
        {
            var query = DC.Set<Person>()
                
                .CheckContain(Searcher.PersonCode, x=>x.PersonCode)
                .CheckContain(Searcher.PersonName, x=>x.PersonName)
                .CheckContain(Searcher.PhoneNumber, x=>x.PhoneNumber)
                .CheckEqual(Searcher.LineCodeId, x=>x.LineCodeId)
                .CheckEqual(Searcher.StationCodeId, x=>x.StationCodeId)
                .CheckEqual(Searcher.Gender, x=>x.Gender)
                .CheckContain(Searcher.Address, x=>x.Address)
                .CheckContain(Searcher.EmpSkills, x=>x.EmpSkills)
                .Select(x => new Person_View
                {
				    ID = x.ID,
                    
                    Person_PersonCode = x.PersonCode,
                    Person_PersonName = x.PersonName,
                    Person_PhoneNumber = x.PhoneNumber,
                    Person_Gender = x.Gender,
                    Person_Address = x.Address,
                    Person_EmpSkills = x.EmpSkills,
                    Person_StationCode = DC.Set<Station>().Where(z0 => z0.StationCode == x.StationCodeId).Select(y => y.StationCode).FirstOrDefault(),
                    Person_LineCode = DC.Set<Line>().Where(z0 => z0.LineCode == x.LineCodeId).Select(y => y.LineCode).FirstOrDefault(),
                })
                .OrderBy(x => x.ID);
            return query;
        }

        
    }
    public class Person_View: Person
    {
        
        public string Person_PersonCode { get; set; }
        public string Person_PersonName { get; set; }
        public string Person_PhoneNumber { get; set; }
        public PersonGenderEnum? Person_Gender { get; set; }
        public string Person_Address { get; set; }
        public string Person_EmpSkills { get; set; }
        public string Person_StationCode { get; set; }
        public string Person_LineCode { get; set; }

    }

}